var express = require('express');
var router = express.Router();
var mongoose=require('./conn.js');

// 4.挂载，定义一个路由处理用户添加文章的请求
router.post('/save_add.html', function(req, res, next) {
  // 接收数据
  var title=req.body.title;
  var category=req.body.category;
  var author=req.body.author;
  var content=req.body.content;
  //写入数据
  var art=new artModel();
  art.title=title; 
  art.category=category; 
  art.author=author; 
  art.content=content; 
  art.time=new Date().toLocaleString(); 
  art.hits=1; 
  console.log(art);
  art.save(function(){
    res.send('<script>alert("添加成功");location.href="list.html";</script>')
  });
});
// 5.创建路由实现显示文章数据
router.get('/list.html',function(req,res){
  artModel.find().exec(function(err,data){
    console.log(data)
    res.render('admin_article_list.ejs',{list:data});
  });
});
module.exports = router;
